package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.Mapper.*;
import com.example.demo.base.Result;
import com.example.demo.entity.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


        import com.baomidou.mybatisplus.core.conditions.Wrapper;
        import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
        import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
        import com.baomidou.mybatisplus.core.toolkit.Wrappers;
        import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
        import com.example.demo.Mapper.UserInfoMapper;
        import com.example.demo.Mapper.UserMapper;
        import com.example.demo.Mapper.QualityUserMapper;
        import com.example.demo.base.Result;
        import com.example.demo.entity.*;
        import org.springframework.beans.BeanUtils;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.*;

        import javax.annotation.Resource;
        import java.util.ArrayList;
        import java.util.List;

@RestController
@RequestMapping({"/userManagement"})
public class UserManagementController {

    @Resource
    UserManagementMapper userManagementMapper;



    /**
     * 分页获取数据库数据
     *  单个的人员管理获取数据
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/pageAll")
    public Result<?> findPageF(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "10") Integer pageSize,
                               @RequestParam String tenantId
    ) {
        LambdaQueryWrapper<User> wrapper = Wrappers.<User>lambdaQuery();
        wrapper.eq(User::getTenantid, Integer.valueOf(tenantId));
        Page<User> userPage = userManagementMapper.selectPage(new Page<>(pageNum,pageSize),wrapper);
        return Result.success(userPage);
    }
    /**
     * 人员管理
     * 单个的根据租户号更新信息
     *
     * @param username
     * @param password
     * @return
     */
    @GetMapping(value = "/update")
    public Result<?> updateById(
                                @RequestParam String username,
                                @RequestParam String password
                               ) {
        if ( username.isEmpty() || password.isEmpty() ) {
            return Result.error(0, "文本不能为空");
        }
        User user = new User( username,password);
        userManagementMapper.updateById(user);
        return Result.success();
    }

}

